const express = require("express");
const router = express.Router();
const routes = require("./routes");
// 初始化中间件
const init_moddleware = require("./middleware/init");
// 鉴权 处理中间件
const token_moddleware = require("./middleware/token");
// 权限 处理中间件
const Auth_moddleware= require("./middleware/auth");
// 微信处理中间件
const wechat_moddleware = require("./middleware/wechat");
// 后处理中间件
const end_moddleware = require("./middleware/end");
// 错误处理中间件
const error_moddleware = require("./middleware/error");
router.use("/wechat", wechat_moddleware);
// 安装中间件
router.use([
  init_moddleware,
  token_moddleware,
  Auth_moddleware,
  end_moddleware,
]);
// 安装路由
for (let route in routes) {
  router.use("/" + route, routes[route]);
}
router.use(error_moddleware)

module.exports = router;
